//
//  UserDetailViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/6/29.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "UserDetailViewController.h"
#import "UserInfoDetailHeaderView.h"
#import "UserjjzjView.h"
#import "UserdsltView.h"

#import "MineViewModel.h"

@interface UserDetailViewController ()
@property (nonatomic,strong) UserInfoDetailHeaderView * infoDetailView;

@property (nonatomic,strong) CMScrollPageView * cmScrollPageView;
@property (nonatomic,strong) UserjjzjView * jjView;
@property (nonatomic,strong) UserdsltView * dsView;

@property (nonatomic,strong) MineViewModel * mineViewModel;

@end

@implementation UserDetailViewController

-(MineViewModel *) mineViewModel{
    if (!_mineViewModel) {
        _mineViewModel = [[MineViewModel alloc] init];
    }
    return _mineViewModel;
}
-(UserInfoDetailHeaderView *) infoDetailView{
    if (!_infoDetailView) {
        _infoDetailView = [[[NSBundle mainBundle] loadNibNamed:@"UserInfoDetailHeaderView" owner:self options:nil]lastObject];
    }
    return _infoDetailView;
}

-(CMScrollPageView *) cmScrollPageView{
    if (!_cmScrollPageView) {
        _cmScrollPageView = [[CMScrollPageView alloc] initWithFrame:CGRectMake(0, _infoDetailView.y + _infoDetailView.height, DEF_DEVICE_WIDTH, DEF_DEVICE_HEIGHT-64 - _infoDetailView.height)];
        [self.view addSubview:_cmScrollPageView];
    }
    return _cmScrollPageView;
}


-(UserjjzjView *) jjView{
    if (!_jjView) {
        _jjView = [[UserjjzjView alloc] initWithFrame:CGRectMake(0, _infoDetailView.y + _infoDetailView.height, DEF_DEVICE_WIDTH, DEF_DEVICE_HEIGHT-64 - _infoDetailView.height)];
    }
    return _jjView;
}

-(UserdsltView *) dsView{
    if (!_dsView) {
        _dsView = [[UserdsltView alloc] initWithFrame:CGRectMake(0, _infoDetailView.y + _infoDetailView.height, DEF_DEVICE_WIDTH, DEF_DEVICE_HEIGHT-64 - _infoDetailView.height)];
    }
    return _dsView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationItem setTitle:@"个人中心"];
    [self.view addSubview:self.infoDetailView];
    
    
    [self initWithUIView];
    
    [self userinfoNetWork];
    
    
}

-(void) userinfoNetWork{
    
    [MXUtility showMBProgress:self.view message:LoadingText];
    [[self.mineViewModel userinfoDetailRequestParameterUserID:self.userID] subscribeNext:^(id x) {
        
        /**
         用户信息
         */
        [self.infoDetailView setDataSourceForUserInfo:self.mineViewModel.userinfoModel];
        self.dsView.userModel =self.mineViewModel.userinfoModel;
        
        
        [MXUtility hideMBProgress:self.view];
    }error:^(NSError *error) {
        [MXUtility hideMBProgress:self.view];
    }];
}

-(void) initWithUIView{
    //将视图添加到标签页上
    NSArray *array = [[NSArray alloc]initWithObjects:self.jjView,self.dsView,nil];
    
    [self.cmScrollPageView setItems:@"竞技战绩" otherItems:@"大神擂台",nil];
    [self.cmScrollPageView setContentOfView:array];
    [self.view addSubview:self.cmScrollPageView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
